package com.ruoyi.web.controller.lhqArDeviceList;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.LhqArDeviceList;
import com.ruoyi.system.service.ILhqArDeviceListService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * AR设备列Controller
 * 
 * @author ruoyi
 * @date 2020-11-21
 */
@Controller
@RequestMapping("/system/list")
public class LhqArDeviceListController extends BaseController
{
    private String prefix = "system/list";

    @Autowired
    private ILhqArDeviceListService lhqArDeviceListService;

    @RequiresPermissions("system:list:view")
    @GetMapping()
    public String list()
    {
        return prefix + "/list";
    }

    /**
     * 查询AR设备列列表
     */
    @RequiresPermissions("system:list:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(LhqArDeviceList lhqArDeviceList)
    {
        startPage();
        List<LhqArDeviceList> list = lhqArDeviceListService.selectLhqArDeviceListList(lhqArDeviceList);
        return getDataTable(list);
    }

    /**
     * 导出AR设备列列表
     */
    @RequiresPermissions("system:list:export")
    @Log(title = "AR设备列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(LhqArDeviceList lhqArDeviceList)
    {
        List<LhqArDeviceList> list = lhqArDeviceListService.selectLhqArDeviceListList(lhqArDeviceList);
        ExcelUtil<LhqArDeviceList> util = new ExcelUtil<LhqArDeviceList>(LhqArDeviceList.class);
        return util.exportExcel(list, "list");
    }

    /**
     * 新增AR设备列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存AR设备列
     */
    @RequiresPermissions("system:list:add")
    @Log(title = "AR设备列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(LhqArDeviceList lhqArDeviceList)
    {
        //新增状态为离线
        lhqArDeviceList.setEquipmentStatus(1);
        return toAjax(lhqArDeviceListService.insertLhqArDeviceList(lhqArDeviceList));
    }

    /**
     * 修改AR设备列
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        LhqArDeviceList lhqArDeviceList = lhqArDeviceListService.selectLhqArDeviceListById(id);
        mmap.put("lhqArDeviceList", lhqArDeviceList);
        return prefix + "/edit";
    }

    /**
     * 修改保存AR设备列
     */
    @RequiresPermissions("system:list:edit")
    @Log(title = "AR设备列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(LhqArDeviceList lhqArDeviceList)
    {
        return toAjax(lhqArDeviceListService.updateLhqArDeviceList(lhqArDeviceList));
    }

    /**
     * 删除AR设备列
     */
    @RequiresPermissions("system:list:remove")
    @Log(title = "AR设备列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(lhqArDeviceListService.deleteLhqArDeviceListByIds(ids));
    }
}
